package com.xbxkj.getway;
import com.xbxkj.getway.config.RequestAuthFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;


@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
@EnableEurekaClient

public class GetWayApplication {
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(r -> r.path("/api/**")
                        .filters(f -> f.filter(new RequestAuthFilter())
                                .addResponseHeader("X-Response-Default-Foo", "Default-Bar"))//定义过滤器需要加这个头
                        .uri("lb://APICONTROLLER")    //路由到的微服务
                        .order(0)       //过滤器的排序   数值越小越先执行
                        .id("controller-route")    //路由器的ID  唯一
                )
   /*             .route(r -> r.path("/api/**")
                        .filters(f -> f.filter(new RequestAuthFilter())
                                .addResponseHeader("X-Response-Default-Foo", "Default-Bar"))//定义过滤器需要加这个头
                        .uri("lb://APICONTROLLER")    //路由到的微服务
                        .order(0)       //过滤器的排序   数值越小越先执行
                        .id("controller-route")    //路由器的ID  唯一
                )*/
                .build();
    }
    public static void main(String[] args) {
        SpringApplication.run(GetWayApplication.class, args);
    }

}
